using Furion.DatabaseAccessor;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Pear.Core;
using Microsoft.Extensions.Caching.Memory;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;

namespace Pear.Application.CloudBlog
{
    /// <summary>
    /// 文章分类管理
    /// </summary>
    [ApiDescriptionSettings(ApiGroupConsts.Cloud_Blog, Name = "articletype")]
    [AllowAnonymous]
    public class ArticleTypeService : IArticleTypeService, IDynamicApiController, ITransient
    {
        /// <summary>
        /// 内存缓存
        /// </summary>
        private readonly IMemoryCache _memoryCache;

        /// <summary>
        /// 分类仓储
        /// </summary>
        private readonly IRepository<ArticleType> _articletypeRepository;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="articletypeRepository"></param>
        /// <param name="memoryCache"></param>
        public ArticleTypeService(IRepository<ArticleType> articletypeRepository
            , IMemoryCache memoryCache)
        {
            _articletypeRepository = articletypeRepository;
            _memoryCache = memoryCache;
        }

        /// <summary>
        /// 获取所有分类
        /// </summary>
        /// <returns></returns>
        public async Task<List<ArticleTypeDto>> GetArticleTypeAllAsync()
        {
            var articletype = await _articletypeRepository.AsAsyncEnumerable();
            return articletype.Adapt<List<ArticleTypeDto>>();
        }
    }
}